//
//  ConfirmOrderController.swift
//  KPUserCenter
//
//  Created by Mr.Lee on 2024/4/23.
//

import DDBase
import KPAppKit


public class KPOrderConfirmController: DDTableViewController<KPOrderModel> {
    var labelList = ["Importe de reembolso", "Tenencia", "Fecha de reembolso", "Intereses y IVA"]
    var labelText1 = "$ 10125"
    var labelText2 = "91 dys"
    var labelText3 = "2021-07-05"
    var labelText4 = "$ 125"
    var bankName = "BBVA"
    var bankNo = "1233 3232 3232 3232"
    
    private lazy var headerView: UIView = UIView(frame: UIScreen.main.bounds)
    
    public override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "Información del Préstamo";
        self.navigationItem.largeTitleDisplayMode = UINavigationItem.LargeTitleDisplayMode.automatic;
    }
    
    public override func createUI() {
        super.createUI()
        self.tableView.tableHeaderView = self.headerView
        
        
        // 顶部 tips
        let label = UILabel()
        label.text = "Revise cuidadosamente sus tarifas y el programa de pago antes de presentar su solicitud."
        label.numberOfLines = 0
        label.textAlignment = .left
        label.layerCornerRadius = 10
        label.backgroundColor = UIColor.hex(hexString: "#FFF0E5")
        label.font = UIFont.systemFont(ofSize: 16, weight:.regular)
        label.textColor = UIColor.hex(hexString: "#FF8B33")
        label.frame = CGRect(x: 16, y: 20, width: UIScreen.main.bounds.width - 32, height:  48)
        self.headerView.addSubview(label)
        
        // 借款信息Información de tarifas
        let label2 = UILabel()
        label2.text = "Información de tarifas"
        label2.numberOfLines = 0
        label2.textAlignment = .left
        label2.font = UIFont.systemFont(ofSize: 16, weight:.bold)
        label2.frame = CGRect(x: 16, y: 88, width: UIScreen.main.bounds.width - 32, height:  48)
        self.headerView.addSubview(label2)
        
        // Create a container view
        let containerView = UIView(frame: CGRect(x: 16, y: 140, width: UIScreen.main.bounds.width - 32, height: 232))
        containerView.layer.cornerRadius = 10
        containerView.layer.borderWidth = 1
        containerView.layer.borderColor = UIColor.hex(hexString: "#EFEFEF").cgColor
        containerView.clipsToBounds = true
        self.headerView.addSubview(containerView)
        
        // Create rows
        let rowHeight: CGFloat = 58
        let rowCount = 4
        for i in 0..<rowCount {
            let rowY = CGFloat(i) * rowHeight
            
            // Add separator
            if i != 0 {
                let separator = UIView(frame: CGRect(x: 0, y: rowY, width: containerView.frame.width, height: 1))
                separator.backgroundColor = UIColor.hex(hexString: "#EFEFEF")
                containerView.addSubview(separator)
            }
            
            // Add left label
            let labelLeft = UILabel(frame: CGRect(x: 20, y: rowY, width: containerView.frame.width - 52, height: rowHeight))
            labelLeft.text = labelList[i] // Replace with your text
            labelLeft.textAlignment = .left
            containerView.addSubview(labelLeft)
            
            // Add Right label
            let label = UILabel(frame: CGRect(x: 20, y: rowY, width: containerView.frame.width - 52, height: rowHeight))
            label.text = if (i == 0) {
                labelText1
            } else if (i == 1) {
                labelText2
            }  else if (i == 2) {
                labelText3
            }  else if (i == 3) {
                labelText4
            }else{
                ""
            } // Replace with your text
            label.textAlignment = .right
            label.textColor = if (i == 0) {
                UIColor.hex(hexString: "#EA5B5B")
            }else{
                UIColor.black
            }
            label.font = if (i == 0) {
                UIFont.systemFont(ofSize: 24, weight:.bold)
            }else{
                UIFont.systemFont(ofSize: 16, weight:.bold)
            }
            containerView.addSubview(label)
        }
        
        // 中间的选产品
        let productView = UIView(frame: CGRect(x: 16, y: 400, width: UIScreen.main.bounds.width - 32, height: 186))
        productView.layer.cornerRadius = 10
        productView.layer.borderWidth = 1
        productView.layer.borderColor = UIColor.hex(hexString: "#EFEFEF").cgColor
        productView.clipsToBounds = true
        self.headerView.addSubview(productView)
        
        
        var productT1 = UILabel(frame: CGRect(x: 20, y: 20, width: containerView.frame.width - 100, height: 20))
        productT1.text = "No se requiere información"
        productT1.textColor = UIColor.hex(hexString: "#F16800")
        productT1.font = UIFont.systemFont(ofSize: 16, weight:.bold)
        productView.addSubview(productT1)
        
        var productT2 = UILabel(frame: CGRect(x: 20, y: 40, width: containerView.frame.width - 100, height: 20))
        productT2.text = "Aprobar inmediatamente"
        productT2.textColor = UIColor.hex(hexString: "#8492A6")
        productT2.font = UIFont.systemFont(ofSize: 12, weight:.regular)
        productView.addSubview(productT2)
        
        // Add right icon
        let arrowImageView = UIImageView(frame: CGRect(x: containerView.frame.width - 94, y: 6, width: 64, height: 64))
        arrowImageView.contentMode = .scaleAspectFit
        arrowImageView.image = UIImage(named: "pic-money") // Use system image for arrow
        arrowImageView.tintColor = .black
        productView.addSubview(arrowImageView)
        
        // todo 横向滑动的 listview
        
        
        // 银行信息
        let label3 = UILabel()
        label3.text = "Banco de recibo"
        label3.numberOfLines = 0
        label3.textAlignment = .left
        label3.font = UIFont.systemFont(ofSize: 16, weight:.bold)
        label3.frame = CGRect(x: 16, y: 600, width: UIScreen.main.bounds.width - 32, height:  48)
        self.headerView.addSubview(label3)
        
        let bankBg = UIImageView(frame: CGRect(x: 16, y: 658, width: UIScreen.main.bounds.width - 32, height: 107))
        bankBg.contentMode = .scaleAspectFill
        bankBg.image = UIImage(named: "card-bank") // Use system image for arrow
        bankBg.tintColor = .black
        self.headerView.addSubview(bankBg)
        
        let bankNameView = UILabel()
        bankNameView.text = bankName
        bankNameView.numberOfLines = 0
        bankNameView.textAlignment = .left
        bankNameView.textColor = .white
        bankNameView.font = UIFont.systemFont(ofSize: 16, weight:.bold)
        bankNameView.frame = CGRect(x: 16 + 25, y: 658 + 18, width: UIScreen.main.bounds.width - 32, height:  48)
        self.headerView.addSubview(bankNameView)
        
        let bankNoView = UILabel()
        bankNoView.text = bankNo
        bankNoView.numberOfLines = 0
        bankNoView.textAlignment = .left
        bankNoView.textColor = .white
        bankNoView.font = UIFont.systemFont(ofSize: 16, weight:.bold)
        bankNoView.frame = CGRect(x: 16 + 25, y: 658 + 56, width: UIScreen.main.bounds.width - 32, height:  48)
        self.headerView.addSubview(bankNoView)
        
        
        
        
        
        // 如果header高度不够
        self.headerView.frame = self.headerView.frame.setHeight(2000)
        self.tableView.tableHeaderView = self.headerView
    }
}
